package com.hspedu.web.exception;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice//全局异常处理器
public class MyGlobalExceptionHandler {
    @ExceptionHandler({NumberFormatException.class, ClassCastException.class})
    public String globalException(Exception e, HttpServletRequest request){
        System.out.println("全局异常处理----"+e.getMessage());
        request.setAttribute("reason",e.getMessage());
        return "exception_mes";
     }
}
